package com.b511.swpu.cementbackend.controller;

import com.b511.swpu.cementbackend.dto.input.SysUserInputDto;
import com.b511.swpu.cementbackend.entity.SysRole;
import com.b511.swpu.cementbackend.service.SysRoleService;
import com.b511.swpu.cementbackend.service.SysUserService;
import com.b511.swpu.cementbackend.util.R;
import io.swagger.annotations.Api;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "员工管理", tags = {"员工管理"})
@RestController
@RequestMapping("/user")
public class SysUserController {

    private final SysUserService sysUserService;

    private final SysRoleService sysRoleService;

    public SysUserController(SysUserService sysUserService, SysRoleService sysRoleService) {
        this.sysUserService = sysUserService;
        this.sysRoleService = sysRoleService;
    }

    @GetMapping("/{num}/{size}")
    public R getAllUser(@PathVariable int num, @PathVariable int size) {
        return sysUserService.getAllUser(PageRequest.of(num, size));
    }

    @GetMapping("/role")
    public R getAllRole(){
        return sysRoleService.getAllSysRole();
    }

    @DeleteMapping("/{id}")
    public R deleteUser(@PathVariable String id){
        return sysUserService.deleteUser(id);
    }

    @GetMapping("/{id}")
    public R getUserById(@PathVariable String id){
        return sysUserService.getUserById(id);
    }

}
